<script setup>
const route = useRoute()
const productId = route.params.id

// 模拟获取产品详情
const products = {
  1: {
    id: 1,
    name: '智能手表 Pro',
    price: 2999,
    image: '/images/watch.jpg',
    description: '全天候健康监测，续航持久',
    features: [
      '心率监测',
      '血氧检测',
      '运动追踪',
      '7天续航',
      '防水50米'
    ],
    specs: {
      '屏幕尺寸': '1.78英寸',
      '分辨率': '448x368',
      '电池容量': '450mAh',
      '重量': '52g'
    }
  },
  2: {
    id: 2,
    name: '无线耳机 Max',
    price: 1299,
    image: '/images/earphone.jpg',
    description: '主动降噪，HiFi音质',
    features: [
      '主动降噪',
      'HiFi音质',
      '蓝牙5.3',
      '30小时续航',
      '快速充电'
    ],
    specs: {
      '降噪深度': '40dB',
      '续航时间': '30小时',
      '充电时间': '1.5小时',
      '重量': '260g'
    }
  },
  3: {
    id: 3,
    name: '智能音箱',
    price: 699,
    image: '/images/speaker.jpg',
    description: '语音助手，智能家居控制',
    features: [
      '语音唤醒',
      '智能家居',
      '高保真音质',
      '多房间联动',
      '流媒体播放'
    ],
    specs: {
      '功率': '20W',
      '频响范围': '50Hz-20kHz',
      '麦克风': '6麦克风阵列',
      '重量': '800g'
    }
  },
  4: {
    id: 4,
    name: '平板电脑',
    price: 3999,
    image: '/images/tablet.jpg',
    description: '高清屏幕，轻薄便携',
    features: [
      '11英寸屏幕',
      '120Hz刷新率',
      '8核处理器',
      '全天续航',
      '触控笔支持'
    ],
    specs: {
      '屏幕尺寸': '11英寸',
      '分辨率': '2560x1600',
      '处理器': '8核芯片',
      '重量': '460g'
    }
  }
}

const product = ref(products[productId] || products[1])
</script>

<template>
  <div class="product-detail">
    <div class="container">
      <div class="detail-grid">
        <div class="product-image">
          <img :src="product.image" :alt="product.name" />
        </div>
        
        <div class="product-info">
          <h1>{{ product.name }}</h1>
          <p class="price">¥{{ product.price }}</p>
          <p class="description">{{ product.description }}</p>
          
          <div class="features">
            <h3>核心特性</h3>
            <ul>
              <li v-for="(feature, index) in product.features" :key="index">
                {{ feature }}
              </li>
            </ul>
          </div>
          
          <div class="specs">
            <h3>技术规格</h3>
            <table>
              <tr v-for="(value, key) in product.specs" :key="key">
                <td class="spec-name">{{ key }}</td>
                <td class="spec-value">{{ value }}</td>
              </tr>
            </table>
          </div>
          
          <button class="btn-buy">立即购买</button>
        </div>
      </div>
      
      <div class="back-link">
        <NuxtLink to="/products">← 返回产品列表</NuxtLink>
      </div>
    </div>
  </div>
</template>

<style scoped>
.product-detail {
  padding: 60px 20px;
  min-height: 100vh;
}

.detail-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 60px;
  max-width: 1200px;
  margin: 0 auto 40px;
}

@media (max-width: 768px) {
  .detail-grid {
    grid-template-columns: 1fr;
  }
}

.product-image {
  width: 100%;
  height: 500px;
  background: #f5f5f5;
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  align-items: center;
  justify-content: center;
}

.product-image img {
  width: 100%;
  height: 100%;
  object-fit: cover;
}

.product-info h1 {
  font-size: 36px;
  margin-bottom: 20px;
  color: #333;
}

.price {
  font-size: 32px;
  font-weight: bold;
  color: #667eea;
  margin-bottom: 20px;
}

.description {
  font-size: 18px;
  color: #666;
  margin-bottom: 30px;
  line-height: 1.6;
}

.features, .specs {
  margin-bottom: 30px;
}

.features h3, .specs h3 {
  font-size: 20px;
  margin-bottom: 15px;
  color: #333;
}

.features ul {
  list-style: none;
  padding: 0;
}

.features li {
  padding: 10px 0;
  border-bottom: 1px solid #eee;
  color: #555;
}

.specs table {
  width: 100%;
  border-collapse: collapse;
}

.specs tr {
  border-bottom: 1px solid #eee;
}

.specs td {
  padding: 12px 0;
}

.spec-name {
  color: #888;
  width: 40%;
}

.spec-value {
  color: #333;
  font-weight: 500;
}

.btn-buy {
  width: 100%;
  padding: 18px;
  background: linear-gradient(135deg, #667eea 0%, #764ba2 100%);
  color: white;
  border: none;
  border-radius: 8px;
  font-size: 18px;
  font-weight: bold;
  cursor: pointer;
  transition: transform 0.3s;
}

.btn-buy:hover {
  transform: scale(1.02);
}

.back-link {
  text-align: center;
  margin-top: 40px;
}

.back-link a {
  color: #667eea;
  text-decoration: none;
  font-size: 16px;
}

.back-link a:hover {
  text-decoration: underline;
}
</style>